﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using IP.Core.IPCommon;
using IP.Core.IPData;
using IP.Core.IPUserService;

using WebUS;
using WebDS;
using WebDS.CDBNames;
using System.Data;

public partial class BaoCao_Bao_cao_nhan_vien_theo_ket_qua_lam_viec : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            m_lbl_thong_bao.Text = "";
            load_data_2_cbo_don_vi();
        }
    }

    #region Members
    US_CM_DM_TU_DIEN m_us_cm_tu_dien = new US_CM_DM_TU_DIEN();
    DS_CM_DM_TU_DIEN m_ds_cm_tu_dien = new DS_CM_DM_TU_DIEN();
    //US_V_BAO_TRI_THIET_BI m_us_v_gd_bao_tri = new US_V_BAO_TRI_THIET_BI();
    //DS_V_BAO_TRI_THIET_BI m_v_ds_gd_bao_tri = new DS_V_BAO_TRI_THIET_BI();
    //DataEntryFormMode m_init_mode = DataEntryFormMode.ViewDataState;
    #endregion

    #region Public Interfaces

    #endregion

    #region Private Methods
    private void load_data_2_cbo_don_vi()
    {
        DS_DM_DIA_PHUONG_BENH_VIEN v_ds_benh_vien = new DS_DM_DIA_PHUONG_BENH_VIEN();
        US_DM_DIA_PHUONG_BENH_VIEN v_us_benh_vien = new US_DM_DIA_PHUONG_BENH_VIEN();
        // Load đợt thanh toán dựa vào tháng và năm thanh toán
        v_us_benh_vien.Fill_data_by_id_cha_va_loai(v_ds_benh_vien, 0, (decimal)e_loai_dia_phuong.BENH_VIEN, 1);
        m_cbo_ten_don_vi.DataTextField = DM_DIA_PHUONG_BENH_VIEN.TEN_DIA_PHUONG;
        m_cbo_ten_don_vi.DataValueField = DM_DIA_PHUONG_BENH_VIEN.ID;
        m_cbo_ten_don_vi.DataSource = v_ds_benh_vien.DM_DIA_PHUONG_BENH_VIEN;
        m_cbo_ten_don_vi.DataBind();
        if (m_cbo_ten_don_vi.Items.Count == 0)
        {
            m_cmd_xuat_file_excel1.Enabled = false;
            m_lbl_thong_bao.Text = "Không có đợt bảo trì nào tại bệnh viện này";
            m_grv_ds_dot_bao_tri.DataSource = null;
            m_grv_ds_dot_bao_tri.DataBind();
        }
        else
        {
            m_cmd_xuat_file_excel1.Enabled = true;
            fill_data_2_grv_dot_bao_tri(CIPConvert.ToDecimal(m_cbo_ten_don_vi.SelectedValue));
        }
    }
    private void load_data_2_excel_search(decimal ip_dc_id_dot_tt)
    {

    }

    private void fill_data_2_grv_dot_bao_tri(decimal ip_dc_id_dot)
    {

    }
    #endregion

    //#region Export Excel
    //private void loadDSExprort(ref string strTable)
    //{
    //    int v_i_so_thu_tu = 0;
    //    // Mỗi cột dữ liệu ứng với từng dòng là label
    //    foreach (DataRow grv in this.m_v_d.V_GD_THANH_TOAN.Rows)
    //    {
    //        strTable += "\n<tr>";
    //        strTable += "\n<td style='width:12%;' class='cssTitleReport' nowrap='nowrap'>" + ++v_i_so_thu_tu + "</td>";
    //        strTable += "\n<td style='width:12%;' class='cssTitleReport' nowrap='nowrap'>" + CIPConvert.ToStr(grv[V_GD_THANH_TOAN.SO_HOP_DONG]).Trim() + "</td>";
    //        strTable += "\n<td style='width:12%;' class='cssTitleReport' nowrap='nowrap'>" + mapping_loai_hop_dong_gv(CIPConvert.ToDecimal(grv[V_GD_THANH_TOAN.ID_HOP_DONG_KHUNG])) + "</td>";
    //        strTable += "\n<td style='width:12%;' class='cssTitleReport' nowrap='nowrap'>" + mapping_don_vi_quan_ly(CIPConvert.ToDecimal(grv[V_GD_THANH_TOAN.ID_DON_VI_QUAN_LY])) + "</td>";
    //        strTable += "\n<td style='width:12%;' class='cssTitleReport' nowrap='nowrap'>" + mapping_time_to_str(grv[V_GD_THANH_TOAN.GHI_CHU_THOI_GIAN_LOP_MON]) + "</td>";
    //        strTable += "\n<td style='width:12%;' class='cssTitleReport' nowrap='nowrap'>" + mapping_magv_by_id(CIPConvert.ToDecimal(grv[V_GD_THANH_TOAN.ID_GIANG_VIEN])) + "</td>";
    //        strTable += "\n<td style='width:12%;' class='cssTitleReport' nowrap='nowrap'>" + CIPConvert.ToStr(grv[V_GD_THANH_TOAN.TEN_GIANG_VIEN]).Trim() + "</td>";
    //        strTable += "\n<td style='width:12%;' class='cssTitleReport' nowrap='nowrap'>" + "'" + mapping_string(grv[V_GD_THANH_TOAN.SO_TAI_KHOAN]) + "</td>";
    //        strTable += "\n<td style='width:12%;' class='cssTitleReport' nowrap='nowrap'>" + mapping_string(grv[V_GD_THANH_TOAN.TEN_NGAN_HANG]) + "</td>";
    //        strTable += "\n<td style='width:12%;' class='cssTitleReport' nowrap='nowrap'>" + "'" + mapping_string(grv[V_GD_THANH_TOAN.MA_SO_THUE]) + "</td>";
    //        strTable += "\n<td style='width:12%;' class='cssTitleReport' nowrap='nowrap'>" + mapping_so_tien(grv[V_GD_THANH_TOAN.GIA_TRI_HOP_DONG]) + "</td>";
    //        strTable += "\n<td style='width:12%;' class='cssTitleReport' nowrap='nowrap'>" + mapping_item_field_nghiem_thu_lop_mon(CIPConvert.ToStr(grv[V_GD_THANH_TOAN.LOAI_HOP_DONG]), grv[V_GD_THANH_TOAN.REFERENCE_CODE], grv[V_GD_THANH_TOAN.GIA_TRI_NGHIEM_THU_THUC_TE]) + "</td>";
    //        strTable += "\n<td style='width:12%;' class='cssTitleReport' nowrap='nowrap'>" + mapping_item_field_ten_cac_mon(CIPConvert.ToStr(grv[V_GD_THANH_TOAN.LOAI_HOP_DONG]), grv[V_GD_THANH_TOAN.GHI_CHU_CAC_MON_PHU_TRACH]) + "</td>";
    //        strTable += "\n<td style='width:12%;' class='cssTitleReport' nowrap='nowrap'>" + mapping_so_tien(grv[V_GD_THANH_TOAN.DA_THANH_TOAN]) + "</td>";
    //        strTable += "\n<td style='width:12%;' class='cssTitleReport' nowrap='nowrap'>" + mapping_so_tien(grv[V_GD_THANH_TOAN.TONG_TIEN_THANH_TOAN]) + "</td>";
    //        strTable += "\n<td style='width:12%;' class='cssTitleReport' nowrap='nowrap'>" + mapping_so_tien(grv[V_GD_THANH_TOAN.SO_TIEN_THUE]) + "</td>";
    //        strTable += "\n<td style='width:12%;' class='cssTitleReport' nowrap='nowrap'>" + mapping_so_tien(grv[V_GD_THANH_TOAN.TONG_TIEN_THUC_NHAN]) + "</td>";
    //        strTable += "\n<td style='width:12%;' class='cssTitleReport' nowrap='nowrap'>" + mapping_so_tien_con_phai_tt(grv[V_GD_THANH_TOAN.CON_PHAI_THANH_TOAN], grv[V_GD_THANH_TOAN.LOAI_HOP_DONG], grv[V_GD_THANH_TOAN.REFERENCE_CODE]) + "</td>";
    //        strTable += "\n<td style='width:12%;' class='cssTitleReport' nowrap='nowrap'>" + mapping_trang_thai_thanh_toan(CIPConvert.ToDecimal(grv[V_GD_THANH_TOAN.ID_TRANG_THAI_THANH_TOAN])) + "</td>";
    //        strTable += "\n<td style='width:12%;' class='cssTitleReport' nowrap='nowrap'>" + mapping_string(grv[V_GD_THANH_TOAN.PO_LAP_THANH_TOAN]) + "</td>";
    //        strTable += "\n<td style='width:12%;' class='cssTitleReport' nowrap='nowrap'>" + mapping_string(grv[V_GD_THANH_TOAN.DESCRIPTION]) + "</td>";
    //        strTable += "\n</tr>";
    //    }
    //}

    //private void loadTieuDe(ref string strTable)
    //{
    //    load_data_2_excel_search(CIPConvert.ToDecimal(m_cbo_dot_thanh_toan.SelectedValue));
    //    strTable += "<table cellpadding='2' cellspacing='0' class='cssTableReport'>";
    //    strTable += "\n<tr>";
    //    strTable += "\n<td><align='center' class='cssTableView' style='width:100%;' nowrap='nowrap'>  </td>";
    //    strTable += "\n<td><align='center' class='cssTableView' style='width:100%;' nowrap='nowrap'>  </td>";
    //    strTable += "\n<td><align='center' class='cssTableView' style='width: 100%;  height: 40px; font-size: large; color:White; background-color:#810C15;' nowrap='wrap'>TRM700 - BÁO CÁO CHI TIẾT THANH TOÁN CỦA ĐỢT THANH TOÁN" + "</td>";
    //    strTable += "\n</tr>";
    //    //
    //    strTable += "\n<tr>";
    //    strTable += "\n<td><align='center' class='cssTableView' style='width:100%;' nowrap='nowrap'>  </td>";
    //    strTable += "\n<td><align='center' class='cssTableView' style='width:100%;' nowrap='nowrap'>  </td>";
    //    strTable += "\n<td><align='center' class='cssTableView' style='width:100%;' nowrap='nowrap'>Đợt thanh toán: " + get_ma_dot_tt_by_id_dot(CIPConvert.ToDecimal(m_cbo_dot_thanh_toan.SelectedValue)) + "</td>";
    //    strTable += "\n</tr>";
    //    //
    //    strTable += "\n<tr>";
    //    strTable += "\n<td><align='center' class='cssTableView' style='width:100%;' nowrap='nowrap'>  </td>";
    //    strTable += "\n<td><align='center' class='cssTableView' style='width:100%;' nowrap='nowrap'>  </td>";
    //    strTable += "\n<td><align='center' class='cssTableView' style='width:100%;' nowrap='nowrap'>Đơn vị thanh toán: " + m_lbl_don_vi_thanh_toan.Text + "</td>";
    //    strTable += "\n</tr>";
    //    //
    //    strTable += "\n<tr>";
    //    strTable += "\n<td><align='center' class='cssTableView' style='width:100%;' nowrap='nowrap'>  </td>";
    //    strTable += "\n<td><align='center' class='cssTableView' style='width:100%;' nowrap='nowrap'>  </td>";
    //    strTable += "\n<td><align='center' class='cssTableView' style='width:100%;' nowrap='nowrap'>Thời gian thanh toán: " + m_lbl_ngay_tt_du_kien.Text + "</td>";
    //    strTable += "\n</tr>";
    //    //
    //    strTable += "\n<tr>";
    //    strTable += "\n<td><align='center' class='cssTableView' style='width:100%;' nowrap='nowrap'>  </td>";
    //    strTable += "\n<td><align='center' class='cssTableView' style='width:100%;' nowrap='nowrap'>  </td>";
    //    strTable += "\n<td><align='center' class='cssTableView' style='width:100%;' nowrap='nowrap'>Loại hợp đồng: " + mapping_loai_hop_dong() + "</td>";
    //    strTable += "\n</tr>";
    //    //
    //    strTable += "\n<tr>";
    //    strTable += "\n<td><align='center' class='cssTableView' style='width:100%;' nowrap='nowrap'>  </td>";
    //    strTable += "\n<td><align='center' class='cssTableView' style='width:100%;' nowrap='nowrap'>  </td>";
    //    strTable += "\n<td><align='center' class='cssTableView' style='width:100%;' nowrap='nowrap'>Ngày hoàn tất thanh toán : " + m_lbl_ngay_hoan_tat_tt.Text + "</td>";
    //    strTable += "\n</tr>";
    //    strTable += "\n</table>";
    //    //table noi dung
    //    strTable += "<table cellpadding='2' cellspacing='0' class='cssTableReport'>";
    //    strTable += "\n<tr>";
    //    strTable += "\n<td style='width:12%;' class='cssTableView' nowrap='nowrap'>STT</td>";
    //    strTable += "\n<td style='width:12%;' class='cssTableView' nowrap='nowrap'>Số HĐ</td>";
    //    strTable += "\n<td style='width:12%;' class='cssTableView' nowrap='nowrap'>Loại hợp đồng</td>";
    //    strTable += "\n<td style='width:12%;' class='cssTableView' nowrap='nowrap'>Đơn vị quản lý HĐ</td>";
    //    strTable += "\n<td style='width:12%;' class='cssTableView' nowrap='nowrap'>Thời gian thực hiện lớp môn</td>";
    //    strTable += "\n<td style='width:12%;' class='cssTableView' nowrap='nowrap'>Mã giảng viên</td>";
    //    strTable += "\n<td style='width:12%;' class='cssTableView' nowrap='nowrap'>Họ tên</td>";
    //    strTable += "\n<td style='width:12%;' class='cssTableView' nowrap='nowrap'>Số tài khoản</td>";
    //    strTable += "\n<td style='width:12%;' class='cssTableView' nowrap='nowrap'>Tên ngân hàng</td>";
    //    strTable += "\n<td style='width:12%;' class='cssTableView' nowrap='nowrap'>Mã số thuế</td>";
    //    strTable += "\n<td style='width:12%;' class='cssTableView' nowrap='nowrap'>Tổng giá trị HĐ (VNĐ)</td>";
    //    strTable += "\n<td style='width:12%;' class='cssTableView' nowrap='nowrap'>" + mapping_header_nghiem_thu_lop_mon(m_str_loai_hd) + "</td>";
    //    strTable += "\n<td style='width:12%;' class='cssTableView' nowrap='nowrap'>Tên các môn phụ trách</td>";
    //    strTable += "\n<td style='width:12%;' class='cssTableView' nowrap='nowrap'>Đã thanh toán (VNĐ)</td>";
    //    strTable += "\n<td style='width:12%;' class='cssTableView' nowrap='nowrap'>Tổng tiền thanh toán đợt này (VNĐ)</td>";
    //    strTable += "\n<td style='width:12%;' class='cssTableView' nowrap='nowrap'>Số tiền thuế (VNĐ)</td>";
    //    strTable += "\n<td style='width:12%;' class='cssTableView' nowrap='nowrap'>Tổng tiền thực nhận đợt này (VNĐ)</td>";
    //    strTable += "\n<td style='width:12%;' class='cssTableView' nowrap='nowrap'>Số tiền còn phải thanh toán (VNĐ)</td>";
    //    strTable += "\n<td style='width:12%;' class='cssTableView' nowrap='nowrap'>Trạng thái thanh toán</td>";
    //    strTable += "\n<td style='width:12%;' class='cssTableView' nowrap='nowrap'>PO lập thanh toán</td>";
    //    strTable += "\n<td style='width:12%;' class='cssTableView' nowrap='nowrap'>Ghi chú</td>";
    //    strTable += "\n</tr>";
    //    loadDSExprort(ref strTable);
    //    strTable += "\n</table>";
    //}

    //private string loadExport()
    //{
    //    try
    //    {
    //        string strHTML = "<html xmlns:o='urn:schemas-microsoft-com:office:office'"
    //        + "\n xmlns:x='urn:schemas-microsoft-com:office:excel'"
    //        + "\n xmlns='http://www.w3.org/TR/REC-html40'>"
    //        + "\n <head>"
    //        + "\n <meta http-equiv=Content-Type content='text/html; charset=utf-8'>"
    //        + "\n <meta name=ProgId content=Excel.Sheet>"
    //        + "\n <meta name=Generator content='Microsoft Excel 11'>"
    //        + "\n <link rel=File-List href='Book1_files/filelist.xml'>"
    //        + "\n <style id='Book1_28091_Styles'><!--table"
    //        + "\n 	{mso-displayed-decimal-separator:'\\.';"
    //        + "\n 	mso-displayed-thousand-separator:'\\,';}"
    //        + ".cssTitleReport"
    //        + "{font-family: tahoma; font-size: 11px;font-weight:normal;border: 1px #000000 solid;text-align:left;}"
    //        + ".cssTableView"
    //        + "{color:#FFFFFF;background-color:#800000;font-family: tahoma,Arial,Times New Roman; font-size: 12px;font-weight:bold;border: 1px #000000 solid;}"
    //        + "\n 	--></style>"
    //        + "\n 	</head>"
    //        + "\n 	<body><div id='Book1_28091' align=center x:publishsource='Excel'>";
    //        string strTable = "";
    //        loadTieuDe(ref strTable);
    //        strHTML += strTable;
    //        strHTML += "\n </div></body> ";
    //        strHTML += "\n </html> ";

    //        return strHTML;
    //    }
    //    catch
    //    {
    //        return "";
    //    }
    //}
    //#endregion

    #region Events

    protected void m_cmd_xuat_file_excel1_Click(object sender, EventArgs e)
    {
        try
        {
            string html = "";// loadExport();
            string strNamFile = "BaoCaoDSThanhToanTheoDot" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + ".xls";
            Response.Cache.SetExpires(DateTime.Now.AddSeconds(1));
            Response.Clear();
            Response.AppendHeader("content-disposition", "attachment;filename=" + strNamFile);
            Response.Charset = "UTF-8";
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.ContentType = "text/csv";
            Response.ContentType = "application/vnd.ms-excel";
            this.EnableViewState = false;
            Response.Write("\r\n");
            Response.Write(html);
            HttpContext.Current.ApplicationInstance.CompleteRequest();
        }
        catch (Exception v_e)
        {
            CSystemLog_301.ExceptionHandle(this, v_e);
        }
    }
    protected void m_cbo_ten_don_vi_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            fill_data_2_grv_dot_bao_tri(CIPConvert.ToDecimal(m_cbo_ten_don_vi.SelectedValue));
        }
        catch (Exception v_e)
        {
            CSystemLog_301.ExceptionHandle(this, v_e);
        }
    }
    #endregion
}